home *** CD-ROM | disk | FTP | other *** search
- unit fmAllo;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Grids, StdCtrls, uBase, dmData;
-
- type
- TfrmPaymentAllocation = class(TForm)
- grpSummary: TGroupBox;
- grpCredits: TGroupBox;
- btnPost: TButton;
- btnCancel: TButton;
- btnDefault: TButton;
- grdSummary: TStringGrid;
- grdCredits: TStringGrid;
- procedure grdSummaryTopLeftChanged(Sender: TObject);
- procedure grdCreditsTopLeftChanged(Sender: TObject);
- procedure grdCreditsSetEditText(Sender: TObject; ACol, ARow: Longint;
- const Value: string);
- procedure FormCreate(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure btnCancelClick(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- private
- public
- Credits: TList;
- procedure AddCredit(aCreditNo, aAmount: LongInt);
- procedure DeleteCredit(aCreditNo: LongInt);
- procedure PopulateForm;
- end;
-
- var
- frmPaymentAllocation: TfrmPaymentAllocation;
-
- function ShowPaymentAllocationDlg: TModalResult;
-
- implementation
-
- uses fmpymt;
-
- {$R *.DFM}
-
- { TfrmPaymentAllocation }
-
- function ShowPaymentAllocationDlg: TModalResult;
- begin
- with frmPaymentAllocation do begin
- PopulateForm;
- if grdCredits.RowCount = 1 then
- raise Exception.Create('No credits have been selected for payment');
- Result := ShowModal;
- end;
- end;
-
- procedure TfrmPaymentAllocation.AddCredit(aCreditNo, aAmount: LongInt);
- begin
- with grdCredits do begin
- Credits.Add(Pointer(aCreditNo));
- RowCount := RowCount + 1;
- FixedRows := 1;
- Cells[0, RowCount - 1] := Format(mskCurrency, [aAmount * 1.0]); { Amount }
- Cells[1, RowCount - 1] := Format(mskCurrency, [aAmount * 1.0]); { Amount remaining }
- end;
- end;
-
- procedure TfrmPaymentAllocation.DeleteCredit(aCreditNo: LongInt);
- begin
- Credits.Remove(Pointer(aCreditNo));
- end;
-
- procedure TfrmPaymentAllocation.PopulateForm;
- var
- I: Integer;
- Total: LongInt;
- PaymentAmount: LongInt;
- begin
- with grdSummary do begin
- Total := 0;
- for I := FixedCols to ColCount do begin
- with frmPayment.grdPayment do
- PaymentAmount := GetCellAmount(Cells[1, I - 1]);
- Inc(Total, PaymentAmount);
- Cells[I, 1] := Format(mskCurrency, [PaymentAmount * 1.0]);
- Cells[I, 2] := Format(mskCurrency, [PaymentAmount * 1.0]);
- end;
-
- { update total payment and total remaining }
- Cells[1, 1] := Format(mskCurrency, [Total * 1.0]);
- Cells[1, 2] := Format(mskCurrency, [Total * 1.0]);
- end;
- end;
-
- procedure TfrmPaymentAllocation.grdSummaryTopLeftChanged(Sender: TObject);
- begin
- { keeps the two grids synchronized when scrolling }
- grdCredits.LeftCol := grdSummary.LeftCol;
- end;
-
- procedure TfrmPaymentAllocation.grdCreditsTopLeftChanged(Sender: TObject);
- begin
- { keeps the two grids synchronized when scrolling }
- grdSummary.LeftCol := grdCredits.LeftCol;
- end;
-
- procedure TfrmPaymentAllocation.grdCreditsSetEditText(Sender: TObject;
- ACol, ARow: Longint; const Value: string);
- var
- Total: LongInt;
- I: Integer;
- TotalRemaining: LongInt;
- P: LongInt;
- begin
- with grdCredits do
- begin
- if (ACol >= FixedCols) and (ARow >= FixedRows) then begin
-
- with grdSummary do begin
- { get current total payment remaining, subtract out the previous
- total for the affected payment method }
- TotalRemaining := GetCellAmount(Cells[1, 2]) - GetCellAmount(Cells[ACol, 2]);
-
- { Recompute the amount remaining for the payment method }
- Total := GetCellAmount(Cells[ACol, FixedRows]);
- with grdCredits do
- for I := FixedRows to RowCount - 1 do begin
- P := GetCellAmount(Cells[ACol, I]);
- Dec(Total, P);
- end;
- Inc(TotalRemaining, Total);
- Cells[ACol, FixedRows + 1] := Format(mskCurrency, [Total * 1.0]);
-
- { display new total remaining }
- Cells[1, 2] := Format(mskCurrency, [TotalRemaining * 1.0]);
- end;
-
- { Recompute the amount remaining for the credit }
- with grdCredits do begin
- Total := GetCellAmount(Cells[0, ARow]);
- for I := FixedCols to ColCount - 1 do
- Dec(Total, GetCellAmount(Cells[I, ARow]));
- Cells[1, ARow] := Format(mskCurrency, [Total * 1.0]);
- end;
- end;
- end;
- end;
-
- procedure TfrmPaymentAllocation.FormCreate(Sender: TObject);
- var
- I: Integer;
- begin
- Credits := TList.Create;
-
- { Display the headers for the summary grid }
- with grdSummary do begin
- Cells[0, 1] := 'Payment Amount';
- Cells[0, 2] := 'Amount Remaining';
- Cells[1, 0] := 'Total';
-
- with dmDataModule.PaymentMethodsList do begin
- ColCount := Count + 2;
- for I := 0 to Count - 1 do begin
- Cells[I + 2, 0] := Strings[I];
- grdCredits.Cells[I + 2, 0] := Strings[I];
- end;
- end;
- end;
-
- { Display the headers for the allocation grid }
- with grdCredits do begin
- ColCount := grdSummary.ColCount;
- RowCount := 1;
- Cells[0, 0] := 'Amount';
- Cells[1, 0] := 'Remaining';
- end;
- end;
-
- procedure TfrmPaymentAllocation.FormDestroy(Sender: TObject);
- begin
- Credits.Free;
- end;
-
- procedure TfrmPaymentAllocation.FormShow(Sender: TObject);
- begin
- with grdCredits do begin
- Col := FixedCols;
- Row := FixedRows;
- SetFocus;
- end;
- end;
-
- procedure TfrmPaymentAllocation.btnCancelClick(Sender: TObject);
- var
- C, R: Integer;
- begin
- with grdCredits do begin
- for C := FixedCols to ColCount - 1 do begin
- grdSummary.Cells[C, FixedRows + 1] := '';
- for R := FixedRows to RowCount - 1 do
- Cells[C, R] := '';
- end;
- end;
- end;
-
- end.
-